package com.timeDeal.servlet;


import com.timeDeal.bean.PageList;
import com.timeDeal.bean.UserBean;
import com.timeDeal.service.WofabudeService;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by 妮子 on 2016/9/12.
 */

public class WofabudeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserBean  loginedUser=(UserBean) request.getSession().getAttribute("USER");
        String flag =StringUtils.defaultString(request.getParameter("flag"),"0");
        System.out.println(flag);
        int jiafangid=loginedUser.getYonghuid();
        WofabudeService wofabudeService=new WofabudeService();
        String currentpage=StringUtils.defaultString(request.getParameter("currentpage"),"1");
        if(StringUtils.equals(flag,"0")){

                PageList result=wofabudeService.getXuqiuList( jiafangid ,PageList.pagesize,Integer.valueOf(currentpage));
                request.setAttribute("pagelist",result);
                request.getRequestDispatcher("/user/wofabude.jsp").forward(request,response);
            }
        else {

            PageList result = wofabudeService.getShijianList(jiafangid, PageList.pagesize, Integer.valueOf(currentpage));
            request.setAttribute("pagelist", result);
            System.out.println("AAAAAAAAAAAAAAAAAAAAAAA");
            System.out.println(result.getList().size());
            request.getRequestDispatcher("/user/shijianchushou/wofabude.jsp").forward(request, response);
        }
    }
}
